// https://www.hupu.com/home/v1/news?pageNo=4&pageSize=50

let num = 1
const arr = []

function fetchData() {
  console.log('num', num)
  fetch(`https://www.hupu.com/home/v1/news?pageNo=${num}&pageSize=50`).then(r => r.json())
    .then(r => {
      arr.push(...r.data)
      num++
      if (num <= 10) fetchData()
      else downloadText('hupu.json', JSON.stringify(arr))
    })
}

fetchData()

function downloadText(fileName, text) {
  const url = window.URL || window.webkitURL || window;
  const blob = new Blob([text]);
  const saveLink = document.createElement("a");
  saveLink.href = url.createObjectURL(blob);
  // 设置 download 属性
  saveLink.download = fileName;
  saveLink.click();
  url.revokeObjectURL(saveLink.href);
}


